package com.redis.demo.rabbitmq.Direct;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.redis.demo.rabbitmq.Constants.Constants;
import java.io.IOException;
import java.util.concurrent.TimeoutException;



/*
* 路由模式
*
*
* */
public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory=new ConnectionFactory();
        factory.setHost(Constants.HOST);
        factory.setPort(Constants.PORT);
        factory.setUsername(Constants.USERNAME);
        factory.setPassword(Constants.PASSWORD);
        factory.setVirtualHost(Constants.VIRTUALHOST);
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.exchangeDeclare(Constants.DIRECT_EXCHANGE, BuiltinExchangeType.DIRECT,true);
        channel.queueDeclare(Constants.DIRECT_QUEUE1,true,false,false,null);
        channel.queueDeclare(Constants.DIRECT_QUEUE2,true,false,false,null);

        //绑定交换机
        channel.queueBind(Constants.DIRECT_QUEUE1,Constants.DIRECT_EXCHANGE,"a");
        channel.queueBind(Constants.DIRECT_QUEUE2,Constants.DIRECT_EXCHANGE,"a");
        channel.queueBind(Constants.DIRECT_QUEUE2,Constants.DIRECT_EXCHANGE,"b");
        channel.queueBind(Constants.DIRECT_QUEUE2,Constants.DIRECT_EXCHANGE,"c");


        String msg_a="hello rabbitmqaaaaaaaaaaaa";
        channel.basicPublish(Constants.DIRECT_EXCHANGE ,"a",null,msg_a.getBytes());
        String msg_b="hello rabbitmqbbbbbbbbbbbb";
        channel.basicPublish(Constants.DIRECT_EXCHANGE ,"b",null,msg_b.getBytes());
        String msg_c="hello rabbitmqcccccccccccc";
        channel.basicPublish(Constants.DIRECT_EXCHANGE ,"c",null,msg_c.getBytes());
        channel.close();
        connection.close();





    }
}
